package com.example.kx025;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;

//复选框
public class MainActivity extends AppCompatActivity {

    CheckBox like1;
    CheckBox like2;
    CheckBox like3;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        like1 = findViewById(R.id.like1);
        like2 = findViewById(R.id.like2);
        like3 = findViewById(R.id.like3);

        like1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                System.out.println(1);
                if (like1.isChecked()) {
                    like1.getText();
                    Toast.makeText(MainActivity.this, like1.getText(), Toast.LENGTH_SHORT).show();
                }
            }
        });

        like2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (like2.isChecked()) {
                    like2.getText();
                    Toast.makeText(MainActivity.this, like2.getText(), Toast.LENGTH_SHORT).show();
                }
            }
        });

        like3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (like3.isChecked()) {
                    like3.getText();
                    Toast.makeText(MainActivity.this, like3.getText(), Toast.LENGTH_SHORT).show();
                }
            }
        });

    }
}